package sma.iss.generate;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * template class to submit to
 * 
 * @author smarsoll
 * 
 */
public class ISS {

	/** beta in instance */
	private double beta;
	private double yaw = -6000;

	/** beta->yaw */
	private Map<Double, Double> mapYaw = new HashMap<Double, Double>();
	private Map<Double, double[][]> mapData = new HashMap<Double, double[][]>();

	/**
	 * This method will be called once at the beginning of each test case
	 * 
	 * @param beta
	 *            "beta angle" for this test case
	 * @return "yaw angle" which you would like to set
	 */
	public double getInitialOrientation(double beta) {
		this.beta = beta;
		initData();
		return getBestYamForBeta(beta);
	}

	private double getBestYamForBeta(double beta2) {
		log("getBestYamForBeta not coded !");
		return 0.0;
	}


	private void log(String message) {
		System.out.println(message);
	}

	/**
	 * called 92 times for each test case<br>
	 * The alpha angle for that minute will be (360 degrees / 92) * minute
	 * 
	 * @param minute
	 *            values 0, 1, 2, ..., 91
	 * @return 20 elements that describe the angular position and the angular velocity of each of the 10 rotation axes
	 *         of the station at that minute
	 */
	public double[] getStateAtMinute(int minute) {
		return getBestData(beta)[minute];
	}

	private double[][] getBestData(double betaRequested) {
		double minDistance = Double.MAX_VALUE;
		double[][] bestData = null;
		for (Entry<Double, double[][]> entry : mapData.entrySet()) {
			if (Math.abs(entry.getKey() - betaRequested) < minDistance) {
				bestData = entry.getValue();
				minDistance = Math.abs(entry.getKey() - betaRequested);
			}
		}
		log("min distance found = " + minDistance);
		return bestData;
	}

	private void initData() {
		log("initData");
		// === end of start

		{
			double betaData = 70.0;
			// 92 lines
			double[][] lines = new double[92][];
			lines[0] = new double[] { 72.0, 0.0, 181.77575173184948, 0.0, 7.993605777301127E-15, -0.06521739130434782, 342.0, 0.0, 162.0,
					0.0, 15.0, 0.0, 195.0, 0.0, 15.0, 0.0, 195.0, 0.0, 345.0, 0.0, 165.0, 0.0 };

			mapData.put(betaData, lines);
		}

	}

}
